<template>
  <div class="city">
    <div class="top">
      <van-search
        v-model="searchValue"
        placeholder="城市/区域/位置"
        shape="round"
        show-action
        @cancel="onCancel"
      />

      <van-tabs v-model:active="tabActive" color="var(--primary-color)">
        <template v-for="(value, key) in allCity" :key="key">
          <van-tab :title="value.title" :name="key"></van-tab>
        </template>
      </van-tabs>
    </div>

    <div class="content">
      <template v-for="(value, key) in allCity" :key="key">
        <city-group v-show="tabActive === key" :currentGroup="value" />
      </template>
    </div>

  </div>
</template>

<script setup>
import { ref, computed } from "vue";
import { useRouter } from "vue-router";
import { storeToRefs } from "pinia";

import useCityStore from "@/stores/modules/city";

import CityGroup from './cpns/city-group.vue'

// 搜索框功能
const searchValue = ref("");
const router = useRouter();
const onCancel = () => {
  router.back();
};

// tab的切换
const tabActive = ref();
// 请求城市数据
// const allCity = ref({})

// getCityAll().then(res => {
//   allCity.value = res.data
// })

// 从store中获取数据
const cityStore = useCityStore();
cityStore.fetchAllCitiesData();
const { allCity } = storeToRefs(cityStore);

// 获取选中标签后的数据
const currentGroup = computed(() => allCity.value[tabActive.value])
</script>

<style lang="less" scoped>
.city {
  --van-tabs-line-height: 50px;

  .top {
    position: relative;
    z-index: 9;
  }

  .content {
    height: calc(100vh - 98px);
    overflow-y: auto;
  }
}
</style>
